<extend name="Template/index"/>
<block name="title">上传文件</block>

<block name="banner"></block>

<block name="main">
   
    <div class="container">

                <ol class="breadcrumb" style="margin: 10px 0px;">
                    <span class="glyphicon glyphicon-home"></span>
                    <li><a href="{:U('Index/index')}">首页</a></li>
                    <li ><a href="#">资料库</a></li>
                    <li ><a href="#">上传资料</a></li>
                </ol>


        <form class="" method="post" action="" name="file_form">

            <div class="form-group text-left">
                <label>资料名称</label>
                <input class="form-control" name="name"/>
            </div>


            <div class="form-group ">
               <ul id="datum_img"></ul>
                <div id="datum_btn_img">上传效果图</div>
                <input  type="hidden"  name="img" value="">
            </div>


            <div class="form-group ">
                <ul id="datum_file"></ul>
                <div id="datum_btn_file">
                    上传文件
                </div>
                <input type="hidden" name="file" value="">
            </div>

            <div class="form-group ">
               <label>文件分类</label>
                <select name="file_category_id">
                    <option>请选择文件分类</option>
                    <volist name="category" id="val">
                    <option value="{$val.id}">{$val.category_name}</option>
                    </volist>
                </select>
            </div>

            <div class="form-group ">
                <label>文件标签(最多五个)</label>
               <ul class="tag">
                   <li><input type="button" value="添加标签" name="tag[]"/></li>

               </ul>
            </div>


            <div class="form-group">
                <p>资料说明</p>

                <textarea name="content" id="ueditor"></textarea>

            </div>




            <div class="form-group">

             <input type="button" class="btn btn-default " value="上传文件" id="upload_file">

            </div>

          </form>
    </div>


<link rel="stylesheet" href="__PUBLIC__/home/js/webuploader/webuploader.css">
<link rel="stylesheet" href="__PUBLIC__/home/css/datum.css">
<script src="__PUBLIC__/home/js/ueditor/ueditor.config.js"></script>
<script src="__PUBLIC__/home/js/ueditor/ueditor.all.js"></script>
<script src="__PUBLIC__/home/js/ueditor/ueditor.all.js"></script>
 <script src="__PUBLIC__/home/js/webuploader/webuploader.js"></script>
 <script src="__PUBLIC__/home/js/layer/mobile/layer.js"></script>
    <script src="__PUBLIC__/home/js/datum.js"></script>
    <script>
        // 图片上传demo
    $(function() {
        //初始化富文本编辑器
        rich_text();
        //初始化上传图片的参数
        upload_img_config("{:U('datum/img')}");
        //初始化上传文件
        upload_file_config("{:U('datum/datum_file')}");


        $('.tag').on('click', ':button[name^=tag]', function () {

            var lenght = $('.tag li').length;

            if(!lenght){
                $('.tag').append('<li><input type="button" value="添加标签" name="tag[]"/><span class="glyphicon glyphicon-remove input_tag"></span></li>');
            }

            if(lenght>5){
                layer.open({
                    content :'您标签添加到上限',
                });
                $(':button[name^=tag]').attr('disabled','disabled');
            }else {

                $(this).attr({type: 'text', value: ''});
                $(this).parent().append('<span class="glyphicon glyphicon-remove input_tag"></span>');
                $('.tag').append('<li><input type="button" value="添加标签" name="tag[]"/></li>');
            }
        });

        $('.tag').on('click','.input_tag',function () {
            $(this).parent().remove();
            $('input[type=button]').removeAttr('disabled');
        });



        $('#upload_file').click(function () {

            var _data=$('form').serialize();

            $.ajax({
                async:true,
                data :_data,
                type :'post',
                url :"{:U('Datum/upload')}",
                success :function (msg) {

                   if(msg.error){
                        layer.open({
                            content :msg.error,
                        });
                    }else {
                        layer.open({
                           content :msg.success,
                            time:2,
                            end:function () {
                                window.location.href=msg.url;
                            }
                        });
                    }

                }

            });

        });

    });
</script>
</block>